﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DIST.LR.ZHJG.Controls.Chart
{
    public partial class ucVFLinearGaugeSin : UserControl
    {

        public ucVFLinearGaugeSin()
        {
            #region MyRegion
            //SolidColorBrush sb = new SolidColorBrush();
            //sb.Color = Colors.Yellow;
            //System.ComponentModel.TypeConverter conver = new System.ComponentModel.TypeConverter();
            ////Brush br = (Brush)conver.ConvertFromString("#293955");

            //System.ComponentModel.TypeConverter brushConverter = new System.ComponentModel.TypeConverter();
            //BrushConverter brushConverter = new BrushConverter();
            //Brush brush = (Brush)brushConverter.ConvertFromString("#02489D");
            //Brush brush = new SolidColorBrush((Color)brushConverter.ConvertFromString("#3C3C3C"));
            //SolidColorBrush sb = new SolidColorBrush();
            //sb.Color = Colors.Yellow;
            //this.Background = sb;
            //System.ComponentModel.TypeConverter conver = new System.ComponentModel.TypeConverter();
            //SolidColorBrush br = (SolidColorBrush)conver.ConvertFromString("#3C3C3C");

            //System.ComponentModel.TypeConverter brushConverter = new System.ComponentModel.TypeConverter();
            ////BrushConverter brushConverter = new BrushConverter();
            //Brush brush = (Brush)brushConverter.ConvertFromString("#02489D"); 
            #endregion

            SLColorTranslator slTrans1 = new SLColorTranslator();
            SolidColorBrush sBrush1 = slTrans1.GetColorFromHexa("#FBFB8B");
            SLColorTranslator slTrans2 = new SLColorTranslator();
            SolidColorBrush sBrush2 = slTrans1.GetColorFromHexa("#02489D");
            ViewModelLGSin vmlg = new ViewModelLGSin(70, 30, 0, 100, sBrush1,sBrush2);
            InitializeComponent();
            this.DataContext = vmlg;
            this.VFLinearGaugeSin.Loaded += new RoutedEventHandler(VFLinearGaugeSin_Loaded);
        }

        void VFLinearGaugeSin_Loaded(object sender, RoutedEventArgs e)
        {
            var c = sender as Visifire.Gauges.Gauge;
            IEnumerable<TextBlock> lablels = VisualTreeAPI.FindVisualChildren<TextBlock>(c.Parent as System.Windows.Controls.Grid);
            foreach (TextBlock txt in lablels)
            {
                if (txt.Text.ToLower().Contains("trial"))
                {
                    txt.Visibility = System.Windows.Visibility.Collapsed;
                    if (txt.Parent is Border)
                    {
                        (txt.Parent as Border).Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
                    }
                }
            }
        }
    }

    public  class SLColorTranslator 
    {
        public SolidColorBrush GetColorFromHexa(string hexaColor)
        {
            if (hexaColor.Length == 7)
            {
                return new SolidColorBrush(
                Color.FromArgb(
                    255,
                    Convert.ToByte(hexaColor.Substring(1, 2), 16),
                    Convert.ToByte(hexaColor.Substring(3, 2), 16),
                    Convert.ToByte(hexaColor.Substring(5, 2), 16)
                ));
            }
            else
            {
                return new SolidColorBrush(
                Color.FromArgb(
                    Convert.ToByte(hexaColor.Substring(1, 2), 16),
                    Convert.ToByte(hexaColor.Substring(3, 2), 16),
                    Convert.ToByte(hexaColor.Substring(5, 2), 16),
                    Convert.ToByte(hexaColor.Substring(7, 2), 16)
                ));
            }
        }

    }


    public class ViewModelLGSin
    {
        private double _value1;
        private double _value2;
        private double _minimum;
        private double _maxmum;

        private SolidColorBrush _color1;
        private SolidColorBrush _color2;

        public SolidColorBrush Color2
        {
            get { return _color2; }
            set { _color2 = value; }
        }

        public SolidColorBrush Color1
        {
            get { return _color1; }
            set { _color1 = value; }
        }

        public double Value1
        {
            get { return _value1; }
            set { _value1 = value; }
        }
        public double Value2
        {
            get { return _value2; }
            set { _value2 = value; }
        }

        public double Minimum
        {
            get { return _minimum; }
            set { _minimum = value; }
        }

        public double Maxmum
        {
            get { return _maxmum; }
            set { _maxmum = value; }
        }

        public ViewModelLGSin(double value1, double value2, double minimum, double maxmum, SolidColorBrush color1, SolidColorBrush color2)
        {
            this._value1 = value1;
            this._value2 = value1 + value2;
            this._minimum = minimum;
            this._maxmum = maxmum;
            this._color1 = color1;
            this._color2 = color2;
        } 
    }
}
